package com.skyworth.web.admin.dishware.repository;

import com.skyworth.web.admin.dishware.domain.DishwareModel;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

/**
 * Created by lxs on 2016/9/20.
 */
public interface DishwareRepository extends PagingAndSortingRepository<DishwareModel, Long> {
	@Query("SELECT CASE WHEN COUNT(dishware) > 0 THEN 'true' ELSE 'false' END FROM DishwareModel dishware WHERE dishware.name = ?1 and dishware.storeId=?2")
	boolean existByName(String name,long store_id);

	@Query("SELECT CASE WHEN COUNT(dishware) > 0 THEN 'true' ELSE 'false' END FROM DishwareModel dishware WHERE dishware.name = ?1 and dishware.id<>?2 and dishware.storeId=?3")
	boolean existDishware(String name, long id, long store_id);

	@Query("select dishware from DishwareModel dishware where dishware.storeId=?1")
	Page<DishwareModel> allByStoreId(long storeId, Pageable pageable);

}
